<?php
/**
 * Title: HTML Table generator
 * Description: Generates XHTML 1.0 Strict tables
 * @requires The LinkedList package. The packages is used to manges rows and table cells
 * @author Oddleif Halvorsen
 * @version 1.0
 * XHTML 1.0 strict implementation: 100%
 */

include_once("HTMLTag.php");

class Tr extends HTMLTag{
	var $columns;
	var $align;
	var $char;
	var $charoff;
	var $valign;
	
	function Tr(){
		$this->columns = array();
	}
	
	function setAlign($align){ $this->align = $align; }
	function setChar($char){ $this->char = $char;	}
	function setCharOff($charoff){ $this->charoff = $charoff;	}
	function setValign($valign){ $this->valign = $valign;	}

	function getAlign(){ return (isset($this->align) ? $this->align : FALSE);	}
	function getChar(){	return (isset($this->char) ? $this->char : FALSE); }
	function getCharOff(){ return (isset($this->charoff) ? $this->charoff : FALSE);	}
	function getValign(){	return (isset($this->valign) ? $this->valign : FALSE); }

	/**
	 * Sets a row header for the row.
	 */
	function addRowHeader($header){
		if(count($this->columns) == 0)
			array_push($this->columns, $header);
		else
			array_splice($this->columns, 0, count($this->columns), array_merge(array($header), array_slice($this->columns, 0)));
		
	}
	/**
	 * Adds a new cell to the row. 
	 * @param $column Th object || Td object
	 */
	function addColumn($column){
		array_push($this->columns, $column);
	}
	
	function getColumnCount()
	{
		return count($this->columns);
	}
	
	/**
	 * Generates the html code for the td tag
	 * with all the provied attributes and table cell(s) (Th and/or Td's)
	 * @return The html code for the tr tag.
	 */
	function getHtml(){	
		$tr = &$this->setTrAttributes();
		
		//inserts the table cells (th/td)
		foreach($this->columns as $cell)
		{
			$tr .= $cell->getHtml();
		}
		
		$tr .= "</tr>";
		
		return $tr;
	}
	
	/**
	 * Sets the attributes for the table row
	 * @return A tr tag with attributes
	 */
	function setTrAttributes(){
		$tr = "<tr";
		
		if(parent::getAttributes() != FALSE)
			$tr .= parent::getAttributes();

		if($this->getAlign() != FALSE)
			$tr .= " align=\"" . $this->getAlign() . "\"";
		if($this->getChar() != FALSE)
			$tr .= " char=\"" . $this->getChar() . "\"";
		if($this->getCharOff() != FALSE)
			$tr .= " charoff=\"" . $this->getCharOff() . "\"";
		if($this->getValign() != FALSE)
			$tr .= " valign=\"" . $this->getValign() . "\"";
		
		$tr .= ">";
		
		return $tr;
	}
}
?>